package
{
	import flash.display.Bitmap;
	import flash.text.Font;
	import flash.utils.Dictionary;
	
	import starling.text.BitmapFont;
	import starling.text.TextField;
	import starling.textures.Texture;
	import starling.textures.TextureAtlas;

	public class Assets
	{
		[Embed(source="../media/graphics/bgWelcome.jpg")]
		public static const BgWelcome:Class;

		[Embed(source="../media/graphics/bgLayer1.jpg")]
		public static const BgLayer1:Class;


		private static var gameTextures:Dictionary=new Dictionary();
		private static var gameTextureAtlas:TextureAtlas;

		[Embed(source="../media/graphics/mySpritesheet.png")]
		public static const AtlasTextureGame:Class;

		[Embed(source="../media/graphics/mySpritesheet.xml", mimeType="application/octet-stream")]
		public static const AtlasXmlGame:Class;

		[Embed(source="../media/graphics/myGlyphs.png")]
		public static const FontTexture:Class;

		[Embed(source="../media/graphics/myGlyphs.fnt", mimeType="application/octet-stream")]
		public static const FontXML:Class;

		public static var myFont:BitmapFont;

		[Embed(source="../media/fonts/embedded/BADABB__.TTF", fontFamily="MyFontName", embedAsCFF="false")]
		public static var MyFont:Class;

		public static function getFont():BitmapFont
		{
			var fontTexture:Texture=Texture.fromBitmap(new FontTexture());
			var fontXML:XML=XML(new FontXML());
			var font:BitmapFont=new BitmapFont(fontTexture, fontXML);
			TextField.registerBitmapFont(font);
			return font;
		}

		public static function getAtlas():TextureAtlas
		{
			if (gameTextureAtlas == null)
			{
				var texture:Texture=getTexture("AtlasTextureGame");
				var xml:XML=new XML(new AtlasXmlGame());
				gameTextureAtlas=new TextureAtlas(texture, xml);
			}
			return gameTextureAtlas;
		}

		public static function getTexture(name:String):Texture
		{
			if (gameTextures[name] == undefined)
			{
				var bitmap:Bitmap=new Assets[name]();
				gameTextures[name]=Texture.fromBitmap(bitmap);
			}
			return gameTextures[name];
		}
	}
}
